package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.BigCustomer;
import cn.wolfcode.edu.domain.SchoolContact;
import cn.wolfcode.edu.query.BigCustomerQueryObject;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.query.SchoolContactQueryObject;
import cn.wolfcode.edu.service.IBigCustomerService;
import cn.wolfcode.edu.service.ISchoolContactService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by NEUZJ on 2018/7/9.
 */
@Controller
@RequestMapping("/schoolcontact")
public class SchoolConctactContoller {
    @Autowired 
    private ISchoolContactService schoolContactService;
   
    @RequestMapping("")
    public String index() {
        System.out.print("XXXXXXXXXXXx");
        return "schoolcontact";

    }
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(SchoolContactQueryObject qo) {
        PageResult pageResult = schoolContactService.query(qo);
        return pageResult;
    }

    @RequestMapping("/save")
    @ResponseBody
    public JsonResult save(SchoolContact schoolContact) {
        JsonResult jsonResult=new JsonResult();
        try {
            schoolContactService.save(schoolContact);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("出事了");
            return jsonResult;
        }
        return jsonResult;
    }
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult udpate(SchoolContact schoolContact) {
        JsonResult jsonResult=new JsonResult();
        try {
            schoolContactService.update(schoolContact);
        } catch (Exception e) {
            e.printStackTrace();
           jsonResult.remark("出事了");
        }
        return jsonResult;
    }
    //查询所有的大客户,以实现学校联系人下拉列表
    @RequestMapping("/listAllBigCustomer")
    @ResponseBody
    public List<BigCustomer> listAllBigCustomer() {
        System.out.print("9999999999999999999999999999999999");
        JsonResult jsonResult = new JsonResult();
       return schoolContactService.listAllBigCustomer();
    }
   //删除学校联系人
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        try {
            schoolContactService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("出事了");
            return jsonResult;
        }
        return jsonResult;

    }
}
